<template>
    <div>
    <h1>康复理疗信息列表显示</h1>
    项目名称<input type="text" v-model="page.names">
    <input type="button" value="查询" @click="cha">
    <table>
        <thead>
            <tr>
                <td><input type="checkbox"  @change="quan" v-model="sells"></td>
                <td>名称</td>
                <td>佣金</td>
                <td>状态</td>
                <td>人数</td>
                <td>时长</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="m in data">
                <td><input type="checkbox" :value="m.kid" v-model="idssing"></td>
                <td>{{m.kname}}</td>
                <td>{{m.price}}</td>
                <td>{{m.ksates?"启用":"禁用"}}</td>
                <td>{{m.furen}}</td>
                <td>{{m.fushi}}</td>
                <td><input type="button" value="逻辑删除" @click="luodel(m.kid)">
                <input v-if="!m.ksates"  type="button" value="启用" @click="upsates(m.kid,true)">
                <input v-else  type="button" value="禁用" @click="upsates(m.kid,false)">

                </td>
            </tr>
        </tbody>
    </table>
    </div>
    <input type="button" value="首页" @click="fanye(1)">
    <input type="button" value="上一页" @click="fanye(2)">
    <input type="button" value="下一页" @click="fanye(3)">
    <input type="button" value="尾页" @click="fanye(4)">
    一共{{paga.pcount}}页，一共{{paga.count}}行，每页{{page.size}}行，当前第{{page.index}}页
 <select v-model="page.size" @change="rong">
    <option>3</option>
    <option>4</option>
    <option>5</option>
 </select>
 <input type="text" v-model="page.index">
 <input type="button" value="跳转" @click="tiao">

</template>

<script setup lang="ts">
import axios from 'axios';
import { useRouter } from 'vue-router';
import { ref } from 'vue';
import { onMounted } from 'vue';

const sells=ref(false);
const idssing=ref([0])


const quan=()=>
{
    if(sells.value)
{
    for(var i=0;i<data.value.length;i++)
{
    idssing.value.push(data.value[i].kid);
}
}
else{
    idssing.value=[0];
}
}


const data=ref([{
    
    "kid": 0,
  "kname": "",
  "price": "",
  "ksates": true,
  "furen": null,
  "fushi": null

}])


const upsates=(vid:any,vsates:any)=>
{
 axios.get("https://localhost:7076/api/kang/upsates",{params:{id:vid,sates:vsates}}).then(res=>
{
    if(res.data>0)
{
    alert("状态修改成功");
    Getdata();
}
else{
    alert("状态修改失败");
    Getdata();
}
}
 )

}




const luodel=(vid:any)=>
{
if(confirm("确认要删除吗"))
{
    axios.delete("https://localhost:7076/api/kang/luodel",{params:{id:vid}}).then(res=>
        {
            if(res.data>0)
        {
            alert("逻辑删除成功");
            Getdata();
        }
        else{
            alert("逻辑删除失败");
            Getdata();
        }
        }
    )
}
}




const rong=()=>
{
    page.value.index=1;
    Getdata();
}

const tiao=()=>
{
    if(page.value.index>=1&&page.value.index<=paga.value.pcount)
{
    Getdata();
}
}


const cha=()=>
{
    page.value.index=1;
    Getdata();
}


const fanye=(vid:any)=>
{
    if(vid==1)
{
    page.value.index=1;
    Getdata();
}
if(vid==2)
{
    if(page.value.index>1)
{
    page.value.index-=1;
    Getdata();
}
}
if(vid==3)
{
    if(page.value.index<paga.value.pcount)
{
    page.value.index+=1;
    Getdata();
}
}
if(vid==4)
{
    page.value.index=paga.value.pcount;
    Getdata();
}


}



const paga=ref({
    count:0,
    pcount:0
})

const page=ref({
    index:1,
    size:3,
    names:""
})

onMounted(()=>
{
    Getdata();
})


const Getdata=()=>
{
    axios.get("https://localhost:7076/api/kang/fen",{params:page.value}).then(res=>
        {
            data.value=res.data.data;
            paga.value.count=res.data.count;
            paga.value.pcount=Math.ceil(paga.value.count/page.value.size)
        }
    )
}



</script>

<style scoped>

</style>